package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.Category;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface CategoryMapper {
    //添加分类
    @Insert("INSERT INTO category VALUES(NULL,#{type},#{name},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void save(Category category);

    @Select("SELECT *FROM category ORDER BY sort ASC ")
    List<Category> findAll();

    //根据Id删除分类
    @Delete("DELETE FROM category WHERE id=#{id};")
    void deleteById(Long id);

    @Update("UPDATE category SET name=#{name},sort=#{sort},update_time=#{updateTime} WHERE id=#{id}")
    void updateById(Category category);

    //根据type查询类别列表
    List<Category> findByType(Integer type);

    //根据名字id查找菜品
    @Select("SELECT *from category where id=#{id}")
    Category findById(Long categoryId);
}

